﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using CsvHelperPlus;

namespace Strategy.Linkage
{
    public class SectorHelp
    {
        string date;
        static string sectorType;
        string filePath;
        DataTable dt;


        public SectorHelp(string date)
        {
            this.date = date;
            filePath = String.Format(@"P:\T0\CoMov\Data\ConceptSector\{0}\{1}.ConceptSector.csv",sectorType, date);
            dt = CsvHandler.ReadCSV(filePath);
        }

        static public void SetSectorType(string sectorType)
        {
            SectorHelp.sectorType = sectorType;
        }

        static public string GetSectorType()
        {
            return sectorType;
        }


        public List<string> GetSector(string code)
        {
            List<string> sect = dt.AsEnumerable().Where(x=>x["Ticker"].ToString().Substring(0,6) == code).Select(x => x["ConceptSectorName"].ToString() ).ToList();
            return sect;
        }

        public List<string> GetStockInSect(string sect)
        {
            List<string> code = dt.AsEnumerable().Where(x => x["ConceptSectorName"].ToString() == sect).Select(x => x["Ticker"].ToString().Substring(0, 6)).ToList();
            return code;
        }

        public List<string> GetBothInSect(string leader, string follow)
        {
            List<string> sectLeader = GetSector(leader);
            List<string> sectFollow = GetSector(follow);
            var intersectList = sectLeader.Intersect(sectFollow).ToList();
            return intersectList;
        }
    }
}
